package typoker.logic;

import java.util.Arrays;
import java.util.Collections;

public class Deck {
	private static final Card[] originalDeck = populateCards();

	private Card[] cards;
	private int counter;

	private Deck() {
		counter = 0;
		cards = new Card[originalDeck.length];
		
		for (int i = 0; i < originalDeck.length; i++) {
			cards[i] = originalDeck[i];
		}
	}

	private static Card[] populateCards() {
		Card[] temp = new Card[Card.suits.length * Card.ranks.length];

		for (byte i = 0; i < Card.suits.length; i++) {
			for (byte j = 0; j < Card.ranks.length; j++) {
				temp[i * Card.ranks.length + j] = new Card(i, j);
			}
		}
		
		return temp;
	}
	
	private Deck shuffle() {
		Collections.shuffle(Arrays.asList(cards));
		return this;
	}

	public static Deck getDeck() {
		return new Deck();
	}
	
	public static Deck getShuffledDeck() {
		return (new Deck()).shuffle();
	}

	public Card getCard() {
		return cards[counter++];
	}
}